<?php
/**
 * add.php
 * Create on 2015-05-26
 * Create by yuebin
 */
namespace haibao\cms\business;

use \haibao\cms\data\ExclusiveDefine as ExclusiveDefineData; 

class ExclusiveDefine extends \haibao\cms\business\Base{
	
	public static function addExclusiveDefine($model){
		self::checkOperation(self::FUNC_CODE_EXCLUSIVE_ADD);
		if(!isset($model->ExclusiveName)){
			throw new BusinessException('请添加标题');
		}
		if(!isset($model->ExclusiveUrl)){
			throw new BusinessException('请添加地址');
		}
		
		$exclusiveDefineData = new ExclusiveDefineData();
		$exclusiveDefineData->add($model);
		
		self::saveOperateHistory(self::FUNC_CODE_EXCLUSIVE_ADD, $model->toArray(false));
	}
	
	public static function updateExclusiveDefine($model){
		self::checkOperation(self::FUNC_CODE_EXCLUSIVE_EDIT);	
		if(!isset($model->ExclusiveName)){
			throw new BusinessException('请添加标题');
		}
		if(!isset($model->ExclusiveUrl)){
			throw new BusinessException('请添加地址');
		}
		$exclusiveDefineData = new ExclusiveDefineData();
		$exclusiveDefineData->updateById($model->Id, $model);
		
		self::saveOperateHistory(self::FUNC_CODE_EXCLUSIVE_EDIT, $model->toArray(false));
	}
	
	public static function getModelById($exclusiveId){
		if(!$exclusiveId){
			return NULL;
		}
		$exclusiveDefineData = new ExclusiveDefineData();
		return $exclusiveDefineData->getOneById($exclusiveId);
	}
	
	public static function getExclusiveList($filter){
		$exclusiveDefineData = new ExclusiveDefineData();
		return $exclusiveDefineData->getAll($filter);
	}
	
	public static function delExclusive($id){
		self::checkOperation(self::FUNC_CODE_EXCLUSIVE_DEL);
		if (!$id){
			throw new BusinessException('独家Id不能为空',self::DATA_EMPTY);
		}
		$exclusiveDefineData = new ExclusiveDefineData();
		$exclusiveDefineData->removeById($id);
		self::saveOperateHistory(self::FUNC_CODE_EXCLUSIVE_DEL, array($id));
	}
	
}
